<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>主要对手</title>

<script src="../../res/js/jquery-3.1.1.min.js"></script>
    <script src="../../res/js/login_common.js"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
  <style>
    body{margin: 10px;}
    .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    
    #poe {

	width:210px;
	height:30px;
	font-weight: bold;
}

 #btnQuery {

	width:50px;
	height:30px;
	font-weight: bold;
}

    #namea {
        position: relative;
        left: 0px;
        top: 20px;
    }

    #names {

        position: relative;
        left: 200px;
        top: -15px;
    }

    #btnQuery {

        position: relative;
        left: 220px;
        top: -15px;
    }



  </style>
</head>
<body>
<div class="selectaa" id = "namea">
    <ul>
        <li>
            <input type="text" name="rivName" id="poe" placeholder="请输入对手名称">
        </li>
    </ul>
</div>

<div class="layui-inline" id="names">
    <label class="layui-form-label">选择日期</label>
    <div class="layui-input-inline">
        <input type="text" name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
    </div>

    <div class="layui-input-inline">
        <input type="text" name="date" id="date2" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
    </div>

</div>

<input type="button" value="查询" id="btnQuery" />




<table class="layui-hide" id="demo" lay-filter="test"></table>
<table class="layui-hide" id="demo2" lay-filter="test2"></table>
 
<script type="text/html" id="barDemo">
    <!--判断用户权限-->
    {{# if(loginObj.manager.usType=='领导'||loginObj.manager.usType=='专家'){ }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="inquire">查看</a>
    {{# } }}
    {{# if(loginObj.manager.usType=='教练'){ }}
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="inquire">查看</a>
    <button type="button" class="layui-btn layui-btn-xs"  lay-event="edit">编辑</button>
    <button type="button" class="layui-btn layui-btn-xs layui-bg-red" lay-event="del">删除</button>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="export">导出</a>
    {{# } }}
</script>

<script type="text/html" id="barDemo2">
    <a class="layui-btn layui-btn-xs" lay-event="edit2">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del2">删除</a>

</script>



<script src="../../res/layui/layui.js"></script>
<script>
layui.config({
  version: '1568076536616' //为了更新 js 缓存，可忽略
});
 var table2=null;
 var rivid = null;
layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function(){
  var laydate = layui.laydate //日期
 
  ,layer = layui.layer //弹层
  ,table = layui.table //表格



    //日期
    laydate.render({
        elem: '#date'
    });

    //日期
    laydate.render({
        elem: '#date2'
    });



  console.info(loginObj.manager)


  
  //向世界问个好

  //执行一个 table 实例
  table2=table.render({
    elem: '#demo'
    ,height: 570
    ,url: '../../RivalAction/findAll?id='+loginObj.manager.usWaiid+"&type="+loginObj.manager.usType//数据接口
    ,title: '用户表'
    ,page: true //开启分页
    ,toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
    ,cols: [[ //表头
           {type: 'checkbox', fixed: 'left'}
          ,{field: 'rivId', title: '对手编号', width:120 , sort: true, totalRow: true}
          ,{field: 'rivName', title: '对手名称', width:120}
          ,{field: 'rivSex', title: '对手性别', width:120}
          ,{field: 'rivFailing', title: '对手缺点', width:120}
          ,{field: 'rivTechnique', title: '技术风格', width:120}
          ,{field: 'rivTactics', title: '战术风格', width: 120}
          ,{field:'creater', title:'创建人', width:120}
          ,{field:'creatTime', title:'创建时间', width:150,templet: "<div>{{layui.util.toDateString(d.creatTime, 'yyyy-MM-dd')}}</div>"}
      ,{fixed: 'right', width: 250, align:'center', toolbar: '#barDemo'}

    ]]
      ,page:true
      ,limit:10
      ,limits:[10,20,30]
  });

  //监听头工具栏事件
  table.on('toolbar(test)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id)
    data = checkStatus.data; //获取选中的数据


    switch(obj.event){
      case 'add':


    	  layer.open({
    	    type: 2,
    	    title: "新增",
    	    closeBtn: 1, //不显示关闭按钮
    	    shade: [0],
    	    area: ['500px', '400px'],
    	    anim: 2,
    	    content: ['type_indexa.addOrupdate.html'], //iframe的url，no代表不显示滚动条
    	    end: function(){ //此处用于演示
    	    	 table2.reload();
    	      }
    	    })

      break;
      case 'update':
        if(data.length === 0){
          layer.msg('请选择一行');
        } else if(data.length > 1){
          layer.msg('只能同时编辑一个');
        } else {
          layer.alert('编辑 [id]：'+ checkStatus.data[0].id);
        }
      break;


      case 'delete':
    	  if(data.length === 0){
              layer.msg('请选择一行');
            } else {
            	

    			if(confirm("确定需要删除吗?")){
    				var ids = "";
    		          $.each(data,function(index,item){
    		        	  ids+=item.rivId+",";
    		        	
    		          })
    				var url = "../../RivalAction/deleteAll";
    				var data ={ids:ids};
    				$.post(url,data,function(obj){
    					if(obj.num==1){
    						 table2.reload();
    					}else{
    						alert("删除失败!");
    					}
    				})
    			}
            }
          break;
        
      break;
    };g
  });
  
  //监听行工具事件
  table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
      //解析为json字符串保存子页面接收
      JonData =  JSON.stringify(data);
      //alert(JonData); //显示数据
    if(layEvent === 'detail'){
      layer.msg('查看操作');
    } else if(layEvent === 'del'){
      layer.confirm('真的删除行么', function(index){
       // obj.del(); //删除对应行（tr）的DOM结构

        var url="../../RivalAction/delete";
        var data2={rivId:data.rivId};
        $.post(url,data2,function(obj){
            console.info(obj);
        	if(obj.num==1){
        		layer.msg("删除成功",{icon:1},function(){
        			  layer.close(index);
        			  table2.reload();
        		})
        	}else{
        		layer.msg("删除失败",{icon:2},function(){

      		})
        	}
        },"json")
      
        //向服务端发送删除指令
      });
    } else if(layEvent === 'inquire') {
        rivid=data.rivId;
        table3.reload({
            url: "../../RivalResult/findAlls",
            where: {
                id: data.rivId
            },

            page: {curr: 1}
        })

    }
    else if(layEvent === 'edit'){
    	
    	layer.open({
    	    type: 2,
    	    title: "修改",
    	    closeBtn: 1, //不显示关闭按钮
    	    shade: [0],
    	    area: ['500px', '400px'],
    	    anim: 2,
    	    content: ['type_indexa.addOrupdate.html?id='+data.rivId], //iframe的url，no代表不显示滚动条
    	    end: function(){ //此处用于演示
    	    	 table2.reload();
    	      }
    	    })
    	  
    }
    else if (obj.event === 'export') {
        var url = "../../ExportServlet?action=rival&id=" + data.rivId;
        location.href = url;
    }
  });



 
  
  //将日期直接嵌套在指定容器中
  var dateIns = laydate.render({
    elem: '#laydateDemo'
    ,position: 'static'
    ,calendar: true //是否开启公历重要节日
    ,mark: { //标记重要日子
      '0-10-14': '生日'
      ,'2018-08-28': '新版'
      ,'2018-10-08': '神秘'
    } 
    ,done: function(value, date, endDate){
      if(date.year == 2017 && date.month == 11 && date.date == 30){
        dateIns.hint('一不小心就月底了呢');
      }
    }
    ,change: function(value, date, endDate){
      layer.msg(value)
    }
  });
  
 
  
  //上传

 
  //底部信息
	
		$("#btnQuery").on("click",function(){
			table2.reload({

			    where: {
                    rivName: $("#poe").val(),
                    creatTimes: $("#date").val(),
                    creatTimea: $("#date2").val()


			    },
			    page: { curr: 1 }
			});
		})




  /*  $("#btnQuery").on("click",function(){
        table2.reload({
            url: '../../RivalAction/findAll',
            where: {
                creatTimes: $("#date").val(),
                creatTimea: $("#date2").val()
            },
            page: { curr: 1 }
        });
    })*/
	
});
</script>


<script>

    function getPathRootJump(){
        var pathName = window.location.pathname.substring(1);
        var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
        var path_root = window.location.protocol + '//' + window.location.host + '/'+ webName + '/';
        return path_root;
    };


</script>


<script>
    layui.config({
        version: '1568076536616' //为了更新 js 缓存，可忽略
    });
    var table3=null;
    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function(){
        var laydate = layui.laydate //日期

            ,layer = layui.layer //弹层
            ,table = layui.table //表格

        //向世界问个好



        //执行一个 table 实例
        table3=table.render({
            elem: '#demo2'
            ,height: 480
            ,url: '../../RivalResult/findAlls' //数据接口
            ,title: '用户表'
            ,page: true //开启分页
            ,toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'resultId', title: '对手成绩编号', width:120 , sort: true, totalRow: true}
                ,{field: 'matchName', title: '比赛名称', width:120}
                ,{field: 'matchTime', title: '比赛时间', width:120}
                ,{field: 'matchAddr', title: '比赛地点', width:120}
                ,{field: 'matchItem', title: '比赛项目', width:120}
                ,{field: 'matchResult', title: '比赛成绩', width: 120}
                ,{field: 'matchSort', title: '比赛排名', width: 120}
                ,{field:'score', title:'积分', width:120}
                ,{field:'rivName', title:'对手姓名', width:120,}
                ,{field:'creater', title:'创建人', width:120}
                ,{field:'creatTime', title:'创建时间', width:120,templet: "<div>{{layui.util.toDateString(d.creatTime, 'yyyy-MM-dd')}}</div>"}
                ,{fixed: 'right', width: 250, align:'center', toolbar: '#barDemo2'}

            ]]
            ,page:true
            ,limit:10
            ,limits:[10,20,30]
        });

        //监听头工具栏事件
        table.on('toolbar(test2)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'add':


                    layer.open({
                        type: 2,
                        title: "新增",
                        closeBtn: 1, //不显示关闭按钮
                        shade: [0],
                        area: ['500px', '400px'],
                        anim: 2,
                        content: ['type_indexa.addOrupdates.html?ids='+rivid], //iframe的url，no代表不显示滚动条
                        end: function(){ //此处用于演示
                            table3.reload();
                        }
                    })

                    break;
                case 'update':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时编辑一个');
                    } else {
                        layer.alert('编辑 [id]：'+ checkStatus.data[0].id);
                    }
                    break;
                case 'delete':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {


                        if(confirm("确定需要删除吗?")){
                            var ids = "";
                            $.each(data,function(index,item){
                                ids+=item.resultId+",";

                            })
                            var url = "../../RivalResult/deleteAll";
                            var data ={ids:ids};
                            $.post(url,data,function(obj){
                                if(obj.num==1){
                                    table3.reload();
                                }else{
                                    alert("删除失败!");
                                }
                            })
                        }
                    }
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test2)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值



            if(layEvent === 'detail'){
                layer.msg('查看操作');
            } else if(layEvent === 'del2'){
                layer.confirm('真的删除行么', function(index){
                    // obj.del(); //删除对应行（tr）的DOM结构

                    var url="../../RivalResult/delete";
                    var data3={resultId:data.resultId};
                    $.post(url,data3,function(obj){
                        console.info(obj);
                        if(obj.num==1){
                            layer.msg("删除成功",{icon:1},function(){
                                layer.close(index);
                                table3.reload();
                            })
                        }else{
                            layer.msg("删除失败",{icon:2},function(){

                            })
                        }
                    },"json")

                    //向服务端发送删除指令
                });
            } else if(layEvent === 'edit2'){

                layer.open({
                    type: 2,
                    title: "修改",
                    closeBtn: 1, //不显示关闭按钮
                    shade: [0],
                    area: ['500px', '400px'],
                    anim: 2,
                    content: ['type_indexa.addOrupdates.html?id='+data.resultId], //iframe的url，no代表不显示滚动条
                    end: function(){ //此处用于演示
                        table3.reload();
                    }
                })

            }
        });



        //将日期直接嵌套在指定容器中
        var dateIns = laydate.render({
            elem: '#laydateDemo'
            ,position: 'static'
            ,calendar: true //是否开启公历重要节日
            ,mark: { //标记重要日子
                '0-10-14': '生日'
                ,'2018-08-28': '新版'
                ,'2018-10-08': '神秘'
            }
            ,done: function(value, date, endDate){
                if(date.year == 2017 && date.month == 11 && date.date == 30){
                    dateIns.hint('一不小心就月底了呢');
                }
            }
            ,change: function(value, date, endDate){
                layer.msg(value)
            }
        });



        //上传




    });
</script>
</body>
</html>